package com.lagou.edu.ad.controller;

import com.lagou.edu.ad.api.dto.PromotionAdDTO;
import com.lagou.edu.ad.api.dto.PromotionSpaceDTO;
import com.lagou.edu.ad.api.remote.AdRemoteService;
import com.lagou.edu.response.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zlg
 * @create 2021-01-14 0:40
 */
@RestController
@RequestMapping("/ad")
public class AdController {
    @Autowired
    private AdRemoteService adRemoteService;
    
    @RequestMapping("/space/getAllSpaces")
    public ResponseDTO getAllSpaces() {
        final List<PromotionSpaceDTO> allSpaces = adRemoteService.getAllSpaces();
        return ResponseDTO.success(allSpaces);
    }
    
    @PostMapping("/space/saveOrUpdate")
    public ResponseDTO saveOrUpdateSpace(@RequestBody PromotionSpaceDTO spaceDTO) {
        return adRemoteService.saveOrUpdateSpace(spaceDTO);
    }
    
    @GetMapping("/space/getSpaceById")
    public ResponseDTO getSpaceById(@RequestParam("id") Integer id) {
        final PromotionSpaceDTO spaceDTO = adRemoteService.getSpaceById(id);
        return ResponseDTO.success(spaceDTO);
    }
    
    @GetMapping("/getAllAds")
    public ResponseDTO getAllAds() {
        final List<PromotionAdDTO> allAds = adRemoteService.getAllAds();
        return ResponseDTO.success(allAds);
    }
    
    @PostMapping("/saveOrUpdate")
    public ResponseDTO saveOrUpdateAd(@RequestBody PromotionAdDTO adDTO) {
        return adRemoteService.saveOrUpdateAd(adDTO);
    }
    
    @GetMapping("/getAdById")
    public ResponseDTO getAdById(@RequestParam("id") Integer id) {
        final PromotionAdDTO adDTO = adRemoteService.getAdById(id);
        return ResponseDTO.success(adDTO);
    }
    
}
